package com.ccp.dev.form.model;

import com.ccp.dev.core.basic.model.BaseModel;
import com.ccp.dev.core.basic.page.PageBean;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 业务数据模板 Model对象
 *
 * @author zhaowj
 */
@XmlRootElement(name = "dataTemplate")
@XmlAccessorType(XmlAccessType.NONE)
public class DataTemplate extends BaseModel {

    /**
     * 字符串 __ns__
     */
    public static final String NS = "__ns__";

    /**
     * 字符串升序
     */
    public static final String ASC = "ASC";

    /**
     * 字符串降序
     */
    public static final String DESC = "DESC";


    /**
     * 权限类型（显示）=0
     */
    public static final int RIGHT_TYPE_SHOW = 0;
    /**
     * 权限类型（打印）=1
     */
    public static final int RIGHT_TYPE_PRINT = 1;
    /**
     * 权限类型（导出）=2
     */
    public static final int RIGHT_TYPE_EXPORT = 2;
    /**
     * 权限类型（过滤条件）=3
     */
    public static final int RIGHT_TYPE_FILTER = 3;
    /**
     * 权限类型（管理）=4
     */
    public static final int RIGHT_TYPE_MANAGE = 4;

    /**
     * 参数标识(过滤条件KEY)
     */
    public static final String PARAMS_KEY_FILTERKEY = "__filterKey__";
    /**
     * 参数标识(流程定义ID)
     */
    public static final String PARAMS_KEY_DEFID = "__defId__";

    public static final String PARAMS_KEY_ALIAS = "alias";

    /**
     * 参数标识(当前路径)
     */
    public static final String PARAMS_KEY_CTX = "__ctx";
    public static final String PARAMS_KEY_ISQUERYDATA = "__isQueryData";

    /**
     * SQL 条件 and
     */
    public static final String CONDITION_AND = " AND ";

    /**
     * SQL 条件 or
     */
    public static final String CONDITION_OR = " OR ";

    /**
     * 数据来源于自定义表=1
     */
    public static final String SOURCE_CUSTOM_TABLE = "1";
    /**
     * 数据来源于其它表=2
     */
    public static final String SOURCE_OTHER_TABLE = "2";

    /**
     * 新增
     */
    public static final String MANAGE_TYPE_ADD = "add";
    /**
     * 编辑
     */
    public static final String MANAGE_TYPE_EDIT = "edit";
    /**
     * 删除
     */
    public static final String MANAGE_TYPE_DEL = "del";
    /**
     * 批量删除
     */
    public static final String MANAGE_TYPE_BATCH_DEL = "batchDel";
    /**
     * 明细
     */
    public static final String MANAGE_TYPE_DETAIL = "detail";
    /**
     * 导入
     */
    public static final String MANAGE_TYPE_IMPORT = "import";
    /**
     * 导出
     */
    public static final String MANAGE_TYPE_EXPORT = "export";
    /**
     * 打印
     */
    public static final String MANAGE_TYPE_PRINT = "print";
    /**
     * 启动流程
     */
    public static final String MANAGE_TYPE_START = "start";
    /**
     * 重启流程
     */
    public static final String MANAGE_TYPE_RESTART = "reStart";

    /**
     * 业务数据表
     */
    public static final String BUS_TABLE = "BPM_BUS_LINK";
    public static final String BUS_TABLE_PK = "BUS_PK";
    public static final String BUS_TABLE_PK_STR = "BUS_PKSTR";

    /**
     * 日期开始标记
     */
    public static final String DATE_BEGIN = "begin";

    /**
     * 日期结束标记
     */
    public static final String DATE_END = "end";


    /**
     * 分页常量
     */
    public static final String PAGE = "p";
    /**
     * 分页大小常量。
     */
    public static final String PAGESIZE = "z";
    /**
     * 排序常量
     */
    public static final String SORTFIELD = "s";
    /**
     * 排序方向常量
     */
    public static final String ORDERSEQ = "o";

    /**
     * 显示样式 列表
     */
    public static final int STYLE_LIST = 0;

    /**
     * 显示样式 树型
     */
    public static final int STYLE_TREE = 1;

    /**
     * 主键
     */
    @XmlAttribute
    protected String id;

    /**
     * 自定义表ID
     */
    @XmlAttribute
    protected String tableId;

    /**
     * 自定义表单key
     */
    @XmlAttribute
    protected String formKey = "";

    /**
     * 名称
     */
    @XmlAttribute
    protected String name;

    /**
     * 样式：0-列表，1-树形
     */
    @XmlAttribute
    protected Short style = 0;

    /**
     * 是否需要分页：0-不分页，1-分页
     */
    @XmlAttribute
    protected Short needPage = 1;

    /**
     * 分页大小
     */
    @XmlAttribute
    protected Integer pageSize = 20;

    /**
     * 数据模板别名
     */
    @XmlAttribute
    protected String templateAlias;

    /**
     * 数据模板代码
     */
    @XmlAttribute
    protected String templateHtml;

    /**
     * 显示字段
     */
    @XmlAttribute
    protected String displayField;

    /**
     * 条件字段
     */
    @XmlAttribute
    protected String conditionField;

    /**
     * 排序字段
     */
    @XmlAttribute
    protected String sortField;

    /**
     * 管理字段，按钮
     */
    @XmlAttribute
    protected String manageField;

    /**
     * 过滤条件
     */
    @XmlAttribute
    protected String filterField;

    /**
     * 导出字段
     */
    @XmlAttribute
    protected String exportField;

    /**
     * 打印字段
     */
    @XmlAttribute
    protected String printField;

    /**
     * 变量字段
     */
    @XmlAttribute
    protected String varField;

    /**
     * 过滤条件
     */
    @XmlAttribute
    protected Short filterType = 0;

    /**
     * 流程定义Id
     */
    @XmlAttribute
    protected String defId;

    /**
     * 是否查询
     */
    @XmlAttribute
    protected Short isQuery = 1;

    /**
     * 是否过滤
     */
    @XmlAttribute
    protected Short isFilter = 1;

    /**
     * 数据来源（ 1来自自定义表）
     */
    @XmlAttribute
    protected String source = SOURCE_CUSTOM_TABLE;


    /**
     * 以下非数据库字段
     * 分页数据
     */
    private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

    /**
     * 分页bean
     */
    private PageBean pageBean;

    /**
     * 流程定义标题
     */
    private String subject;


    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return this.id;
    }

    public String getTableId() {
        return tableId;
    }

    public void setTableId(String tableId) {
        this.tableId = tableId;
    }

    public String getFormKey() {
        return formKey;
    }

    public void setFormKey(String formKey) {
        this.formKey = formKey;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Short getStyle() {
        return style;
    }

    public void setStyle(Short style) {
        this.style = style;
    }

    public Short getNeedPage() {
        return needPage;
    }

    public void setNeedPage(Short needPage) {
        this.needPage = needPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getTemplateAlias() {
        return templateAlias;
    }

    public void setTemplateAlias(String templateAlias) {
        this.templateAlias = templateAlias;
    }

    public String getTemplateHtml() {
        return templateHtml;
    }

    public void setTemplateHtml(String templateHtml) {
        this.templateHtml = templateHtml;
    }

    public String getDisplayField() {
        return displayField;
    }

    public void setDisplayField(String displayField) {
        this.displayField = displayField;
    }

    public String getConditionField() {
        return conditionField;
    }

    public void setConditionField(String conditionField) {
        this.conditionField = conditionField;
    }

    public String getSortField() {
        return sortField;
    }

    public void setSortField(String sortField) {
        this.sortField = sortField;
    }

    public String getManageField() {
        return manageField;
    }

    public void setManageField(String manageField) {
        this.manageField = manageField;
    }

    public String getFilterField() {
        return filterField;
    }

    public void setFilterField(String filterField) {
        this.filterField = filterField;
    }

    public String getVarField() {
        return varField;
    }

    public void setVarField(String varField) {
        this.varField = varField;
    }

    public Short getFilterType() {
        return filterType;
    }

    public void setFilterType(Short filterType) {
        this.filterType = filterType;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public List<Map<String, Object>> getList() {
        return list;
    }

    public void setList(List<Map<String, Object>> list) {
        this.list = list;
    }

    public PageBean getPageBean() {
        if (pageBean == null) {
            pageBean = new PageBean(1, pageSize);
        }
        return pageBean;
    }

    public void setPageBean(PageBean pageBean) {
        this.pageBean = pageBean;
    }

    public String getDefId() {
        return defId;
    }

    public void setDefId(String defId) {
        this.defId = defId;
    }

    public Short getIsQuery() {
        return isQuery;
    }

    public void setIsQuery(Short isQuery) {
        this.isQuery = isQuery;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public Short getIsFilter() {
        return isFilter;
    }

    public void setIsFilter(Short isFilter) {
        this.isFilter = isFilter;
    }

    public String getExportField() {
        return exportField;
    }

    public void setExportField(String exportField) {
        this.exportField = exportField;
    }

    public String getPrintField() {
        return printField;
    }

    public void setPrintField(String printField) {
        this.printField = printField;
    }

    @Override
    public String toString() {
        return "DataTemplate{" +
                "id='" + id + '\'' +
                ", tableId='" + tableId + '\'' +
                ", formKey='" + formKey + '\'' +
                ", name='" + name + '\'' +
                ", style=" + style +
                ", needPage=" + needPage +
                ", pageSize=" + pageSize +
                ", templateAlias='" + templateAlias + '\'' +
                ", templateHtml='" + templateHtml + '\'' +
                ", displayField='" + displayField + '\'' +
                ", conditionField='" + conditionField + '\'' +
                ", sortField='" + sortField + '\'' +
                ", manageField='" + manageField + '\'' +
                ", filterField='" + filterField + '\'' +
                ", exportField='" + exportField + '\'' +
                ", printField='" + printField + '\'' +
                ", varField='" + varField + '\'' +
                ", filterType=" + filterType +
                ", defId=" + defId +
                ", isQuery=" + isQuery +
                ", isFilter=" + isFilter +
                ", source='" + source + '\'' +
                ", list=" + list +
                ", pageBean=" + pageBean +
                ", subject='" + subject + '\'' +
                '}';
    }
}